
{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id"  lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <!-- 新增的开票状态 -->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">开票状态：</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <select >-->
<!--                                <option value="" >请选择</option>-->
<!--                                <option value="0" >未开票</option>-->
<!--                                <option value="1" >已开票</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>{:__('Reset')}</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="reload"  class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>


<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn  layui-btn-primary layui-btn-xs {:node('Invoice/detail')}" data-title="查看详情" lay-event="detail"><i class="layui-icon">&#xe705;</i></a>
    {{# if(d.status==1&&d.invoice_type==1){ }}
        <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Invoice/blush')}" data-title="冲红发票" lay-event="blush">冲红发票</a>
    {{# } }}
    {{# if(d.status==2&&d.invoice_type==1){ }}
    <a href="javascript:;" class="layui-btn  layui-btn-xs {:node('Invoice/failreason')}" data-title="失败原因" lay-event="failreason">失败原因</a>
    {{# } }}
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky','opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var opTable = layui.opTable;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url:"{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:20
                ,limits:[10,20,30,50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '', type: 'checkbox', fixed: true},
                { title: '商户名',width: 200, field: 'merchant_user',templet:function (item) {
                    if(item.name==''||item.name=='-'){
                        return item.company
                    }else {
                        return item.name
                    }

                }},
                { title: '合同号',width:'10%', field: 'code'},
                { title: '发票抬头',width:'20%', field: 'title',templet:function (item) { return item.title} },
                { title: '发票类型',width:100, field: 'invoice_type',templet:function (item) {
                        var status = item.invoice_type
                        if ( status== 1){
                            return '普票'
                        } else if (status == 2){
                            return '专票'
                        }
                    }},
                { title: '开票状态',width:100, field: 'status',templet:function (item) {
                        var status = item.status
                        if ( status== 1){
                            return '已开票'
                        } else if (status == 2){
                            return '开票失败'
                        }else if(status== 3){
                            return '已冲红';
                        }else if(status== 0){
                            return '申请开票';
                        }
                    }},
                { title: '发票金额',width:'10%', field: 'amount',templet:function (item) { return item.amount/100+'元'} },
                { title: '发票流水号',width:200, field: 'invoiceSerialNum',templet:function (item){
                        var status = item.status
                    if ( status== 1){
                            return item.invoiceSerialNum;
                        }else {
                        return '';
                    }
                    }},
                { title: '发票代码',width:130, field: 'invoiceCode'},
                { title: '发票号码',width:110, field: 'invoiceNo'},
                // { title: '发票流水号',width:'10%', field: 'invoiceSerialNum'},



                { title: '开票时间', field: 'createTime',align:'center',width:200,templet:function (item){
                        return   layui.util.toDateString((item.createTime)*1000)
                    }},
                {templet: '#operationTpl', width: 240,align: 'center', title: '操作',fixed: 'right'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="detail"){
                lucky.CreateOpenForm("查看","{:url('detail')}?id=" + _id+'&electrity_type='+data.electrity_type);
                return false;
            }else if(layEvent==="print"){
                lucky.CreateOpenForm("打印","{:url('common/costPrint')}?id=" + _id,'85%');
                return false;
            }else if(layEvent==="blush"){
                lucky.FormatData(_id,"{:url('blush')}",'确认冲红发票?');
                return false;
            }else if(layEvent==="failreason"){
                lucky.CreateOpenForm("失败原因","{:url('failreason')}?id=" + _id,'85%');
                return false;
            }else if(layEvent==="invoice"){
                var datas = {} ;
                datas.id      = _id ;   //  购买数量
                $.ajax({
                    url:"{:url('invoice')}",
                    type:"post",
                    data: datas,
                    dataType:"json",
                    success:function(data){
                        layer.msg(data.msg,{icon:15,time:1000,shade:0.3});
                        window.location.reload();
                    }
                });
                return false;
            }
        });
        table.on('toolbar(table_id)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(obj.event==="close"){
                opTables.closeAll();
            }else if(obj.event==="open"){
                opTables.openAll();
            }else if(obj.event==="detail"){
                lucky.CreateOpenForm("订单详情","{:url('detail')}");
                return false;
            }else if(obj.event==="reload"){
                lucky.CreateReload();
            }else if(obj.event==="del"){
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.FormatData(id,"{:url('del')}");
                return  false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script >

{/block}
